/**
 *  This is free software licensed and distributed under 
 *  the terms and conditions of the 
 * GNU Lesser General Public License (LGPL) Version 3.0 .
 * 
 * http://www.gnu.org/licenses/lgpl.html
 *
 * @author Markus Kosmal
 */
package org.mko.html5.client;

import java.util.ArrayList;

import org.mko.html5.client.carousel.Carousel;
import org.mko.html5.client.pyramid.Pyramid;

import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.UIObject;

/**
 * The Class SlotMachine.
 * 
 * Warning: Only experimental and not working in all cases
 */
public class SlotMachine extends FlowPanel {

    /** The first carousel. */
    private final Carousel firstCarousel;

    /** The second carousel. */
    private final Carousel secondCarousel;

    /** The third carousel. */
    private Carousel thirdCarousel;

    /** The width. */
    private final int width = 200;

    /** The height. */
    private final int height = 400;

    /** The border offset. */
    private final int borderOffset = 0;

    /** The item count. */
    private final int itemCount = 5;

    /** The border color. */
    private final String borderColor = "transparent";

    /** The is horizontal. */
    private final boolean isHorizontal = true;

    /**
     * Instantiates a new slot machine.
     */
    public SlotMachine() {
        ArrayList<UIObject> list = new ArrayList<UIObject>();

        list.add(new Pyramid(new HTML("firstOne"), new HTML("secondOne"), new HTML("thirdItem"), new HTML("bottomItem")));

        ArrayList<Image> imgSet = new ArrayList<Image>();
        int picNumber = 1;
        for (int i = 0; i < this.itemCount; i++) {
            Image img = new Image("webshopbase/img/part" + picNumber + ".png");
            img.setWidth(this.width - this.borderOffset + "px");
            imgSet.add(img);
            if (picNumber == this.itemCount) {
                picNumber = 1;
            }
            else {
                picNumber++;
            }
        }

        this.secondCarousel = new Carousel(this.width, this.height, this.borderOffset, "transparent", false, imgSet);

        list.add(this.secondCarousel);

        for (int i = 0; i < this.itemCount; i++) {
            Image img = new Image("webshopbase/img/part" + picNumber + ".png");
            img.setWidth(this.width - this.borderOffset + "px");
            list.add(img);
            if (picNumber == this.itemCount) {
                picNumber = 1;
            }
            else {
                picNumber++;
            }
        }

        this.firstCarousel = new Carousel(this.width, this.height, this.borderOffset, this.borderColor, this.isHorizontal, list);
        this.add(this.firstCarousel);
    }

    /**
     * Turn forward.
     */
    public final void turnForward() {
        this.firstCarousel.turnLeft();
        this.secondCarousel.turnLeft();
    }

    /**
     * Turn back.
     */
    public final void turnBack() {
        this.firstCarousel.turnRight();
        this.secondCarousel.turnRight();
    }
}
